package com.sky.mapper.common;

import com.github.pagehelper.Page;
import com.sky.annotation.AutoFill;
import com.sky.dto.DishPageQueryDTO;
import com.sky.enumeration.OperationType;
import com.sky.pojo.Dish;
import com.sky.vo.DishVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface DishMapper {




    /**
     * 根据分类id查询菜品数量
     * @param categoryId
     * @return
     */
    @Select("select count(id) from dish where category_id = #{categoryId}")
    Integer countByCategoryId(Long categoryId);
    /*
    * 增加菜品
    * @param id
    * @return
    * */
    @AutoFill(OperationType.INSERT)
    int insert(Dish dish);
    /*
    * 根据名称查询菜品是否已存在
     */
    @Select("select count(id) from dish where name = #{name}")
    Long countByName(String name);
    /*
    * 根据条件查询菜品及关联的分类信息
    * @param dishPageQueryDTO
    * @return
    * */
    Page<DishVO> selectDishsAndCategory(DishPageQueryDTO dishPageQueryDTO);

    Long countByStatusAndIds(@Param("status") Integer status, @Param("ids")List<Long> ids);

    int deleteByIds(@Param("ids") List<Long> ids);

    DishVO seletDishAndFlavorsById(Long id);
    @AutoFill(OperationType.UPDATE)
    void update(Dish dish);

    @Select("select * from dish where name like concat('%',#{name},'%')")
    List<Dish> selectByNameCategory(Dish dish);



    /**
     * 动态条件查询菜品
     * @param dish
     * @return
     */
    List<Dish> selectByNameStatusCategoryId(Dish dish);
}
